package com.duobeiyun.gmstest.work

import android.content.Context
import android.util.Log
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import com.duobeiyun.generamessagesdk.ErrorInfo
import com.duobeiyun.generamessagesdk.ResultCallback
import com.duobeiyun.generamessagesdk.invite.GmsInvitationEventListener
import com.duobeiyun.generamessagesdk.invite.Invitation
import com.duobeiyun.generamessagesdk.invite.InvitationFailureReason
import com.duobeiyun.gmstest.TestInstance
import com.duobeiyun.gmstest.log.LogDebug
import com.duobeiyun.gmstest.log.LogOuter
import com.duobeiyun.gmstest.work.sample.WorkAsyncMode
import kotlinx.coroutines.CancellableContinuation
import kotlinx.coroutines.suspendCancellableCoroutine
import java.util.*
import kotlin.coroutines.resume

/**
 * 接收邀请测试
 */
class WorkAcceptTest(appContext: Context, workerParams: WorkerParameters) :
        WorkAsyncMode(appContext, workerParams) {

    override fun setNumber() {
        TAG = "WorkAcceptTest"
        number = "7"
    }
    override fun realWork(continuation: CancellableContinuation<Result>) {

        TestInstance.acceptTest(object : GmsInvitationEventListener {
            override fun onFailure(invitation: Invitation, reason: InvitationFailureReason) {

            }

            override fun onArrived(invitation: Invitation) {
                // 收到之后取消

            }

            override fun onCanceled(invitation: Invitation) {

            }

            override fun onAccepted(invitation: Invitation) {

            }

            override fun onRefused(invitation: Invitation) {

            }
        }, object : ResultCallback<Invitation> {
            override fun onSuccess(responseInfo: Invitation?) {
                LogOuter.print("number:$number \t result:${true} \t name:AcceptTest  ")
                continuation.resume(Result.success())
            }

            override fun onFailure(errorInfo: ErrorInfo) {
                LogDebug.logE(errorInfo.toString())
                LogOuter.print("number:$number \tresult:${false} \tname:AcceptTest")
                continuation.resume(Result.success())

            }
        })

    }


}